<?php
namespace Admin\Controller;
use Think\Controller;
class LeaveMsgController extends AdminController{
    /**
     * 公司信息设置
     */
    public function index()
    {
        $Leavemsg = M('Leavemsg');//实例化AdminUser对象
        $count = $Leavemsg->count();// 查询满足要求的总记录数
        $itemNum = 6; //每页显示的记录数
        $show = c_page($count,'条留言');
        //page方法分页
        $data = $Leavemsg
            ->order('c_time desc, id desc')
            ->page(I('get.p',1) . ',' . $itemNum)
            ->select();
//        var_dump($data);
//        exit;
        foreach ($data as $k => $v){
            $data[$k]['msg'] = subtext(strip_tags($v['msg']),30,'...');
        }
        if(IS_AJAX){
            $json['data'] = $data;
            $json['page'] = $show;
            $this->ajaxReturn($json);
        }else{
            $this->assign('title','留言列表');//标题
            $this->assign('data',$data);// 赋值数据集
            $this->assign('page',$show);// 赋值分页输出
            $this->display();
        }
    }

    public  function detail($id=0){
        if($id < 1){
            $this->error("参数错误");
        }
        $one = M('Leavemsg')->find($id);
        $this->ajaxReturn($one);
    }




}